#include "H264VideoDecoder.hpp"
#include "FileReader.hpp"
#include "H264CommonFunction.hpp"
#include "H264SPS.hpp"
#include "H264PPS.hpp"
#include "H264PictureGop.hpp"
#include "H264SliceHeader.hpp"





int H264VideoDecoder::open(const char* filePath){
    std::string filePath = "352x288.h264";
    AnnexBReader reader(filePath);
    int ret = reader.Open();
    if(ret == -1){
        printf("open file failed....\n");
    }
    PictureGop pictureGop;
    while(1){
        Nalu nalu;
        ret = reader.ReadNalu(nalu);
        if(ret){
            break;
        }
        nalu.ParseRBSP();
        nalu.ParseHeader();
        
        switch (nalu.nal_unit_type)
        {
        case H264_NAL_SLICE:   //1
        {   
            SliceHeader sliceheader = nalu;
            sliceheader.Parse(pictureGop.m_sps);

            break;
        }
        case H264_NAL_DPA:    //2
        {

            break;
        }
        case H264_NAL_DPB:   //3
        {

            break;
        }
        case H264_NAL_DPC:   //4
        {   
           
            break;
        }
        case H264_NAL_IDR_SLICE: //5
        {
            SliceHeader sliceheader = nalu;
            sliceheader.Parse(pictureGop.m_sps);

            
            break;
        }
        case H264_NAL_SEI:  //6
        {

            break;
        }
        case H264_NAL_PPS: //7
        {
            NaluPPS pps = nalu;
            pps.Parse(pictureGop.m_sps);
            pictureGop.m_pps[pps.pic_parameter_set_id] = pps;
            break;
        }
        case H264_NAL_SPS: //8
        {
            NaluSPS sps= nalu;
            sps.Parse();
            pictureGop.m_sps[sps.seq_parameter_set_id] = sps;
            break;
        }
            
        default:
            {


                break;
            }   
        }
        

    } 
    
    
    reader.Close();
    return 0;
}


